#include "wxsarraystringeditordlg.h"

#include <wx/tokenzr.h>

#include <wx/button.h>
#include <wx/string.h>
#include <wx/intl.h>

const long wxsArrayStringEditorDlg::ID_TEXTCTRL1 = wxNewId();

#include "prep.h"

BEGIN_EVENT_TABLE( wxsArrayStringEditorDlg, wxScrollingDialog )


END_EVENT_TABLE()

wxsArrayStringEditorDlg::wxsArrayStringEditorDlg( wxWindow* parent, wxArrayString& _Data, wxWindowID id ):
  Data( _Data ) {
  wxBoxSizer* BoxSizer1;
  wxStdDialogButtonSizer* StdDialogButtonSizer1;
  wxStaticBoxSizer* StaticBoxSizer1;
  Create( parent, id, _T( "Edit items" ), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T( "id" ) );
  BoxSizer1 = new wxBoxSizer( wxVERTICAL );
  StaticBoxSizer1 = new wxStaticBoxSizer( wxHORIZONTAL, this, _T( "Enter items (one item per line)" ) );
  Items = new wxTextCtrl( this, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxSize( 350, 200 ), wxTE_MULTILINE | wxVSCROLL | wxHSCROLL, wxDefaultValidator, _T( "ID_TEXTCTRL1" ) );
  StaticBoxSizer1->Add( Items, 1, wxEXPAND, 2 );
  BoxSizer1->Add( StaticBoxSizer1, 1, wxEXPAND, 5 );
  StdDialogButtonSizer1 = new wxStdDialogButtonSizer();
  StdDialogButtonSizer1->AddButton( new wxButton( this, wxID_OK, wxEmptyString ) );
  StdDialogButtonSizer1->AddButton( new wxButton( this, wxID_CANCEL, wxEmptyString ) );
  StdDialogButtonSizer1->Realize();
  BoxSizer1->Add( StdDialogButtonSizer1, 0, wxALL | wxEXPAND, 5 );
  SetSizer( BoxSizer1 );
  BoxSizer1->Fit( this );
  BoxSizer1->SetSizeHints( this );
  Connect( wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED, ( wxObjectEventFunction )&wxsArrayStringEditorDlg::OnOK );
  Connect( wxID_CANCEL, wxEVT_COMMAND_BUTTON_CLICKED, ( wxObjectEventFunction )&wxsArrayStringEditorDlg::OnCancel );
  size_t Count = Data.Count();
  for( size_t i = 0; i < Count; i++ ) {
    Items->AppendText( Data[i] );
    Items->AppendText( _T( '\n' ) );
  }
}

wxsArrayStringEditorDlg::~wxsArrayStringEditorDlg() {
}


void wxsArrayStringEditorDlg::OnOK( M_Code_unused wxCommandEvent& event ) {
  wxStringTokenizer Tknz( Items->GetValue(), _T( "\n" ), wxTOKEN_RET_EMPTY );
  Data.Clear();
  while( Tknz.HasMoreTokens() ) {
    wxString Line = Tknz.GetNextToken();
    Data.Add( Line );
  }
  EndModal( wxID_OK );
}

void wxsArrayStringEditorDlg::OnCancel( M_Code_unused wxCommandEvent& event ) {
  EndModal( wxID_CANCEL );
}
